﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.CampaignBehaviors.OrderOfBattleCampaignBehavior
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.CampaignBehaviors
{
  public class OrderOfBattleCampaignBehavior : CampaignBehaviorBase
  {
    private List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData> _siegeFormationInfos;
    private List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData> _fieldBattleFormationInfos;

    public OrderOfBattleCampaignBehavior()
    {
      this._siegeFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>();
      this._fieldBattleFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>();
    }

    public override void RegisterEvents()
    {
    }

    public override void SyncData(IDataStore dataStore)
    {
      if (dataStore.SyncData<List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>>("_siegeFormationInfos", ref this._siegeFormationInfos) && this._siegeFormationInfos == null)
        this._siegeFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>();
      if (!dataStore.SyncData<List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>>("_formationInfos", ref this._fieldBattleFormationInfos) || this._fieldBattleFormationInfos != null)
        return;
      this._fieldBattleFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>();
    }

    public OrderOfBattleCampaignBehavior.OrderOfBattleFormationData GetFormationDataAtIndex(
      int formationIndex,
      bool isSiegeBattle)
    {
      return isSiegeBattle ? (this._siegeFormationInfos.Count > formationIndex ? this._siegeFormationInfos[formationIndex] : (OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) null) : (this._fieldBattleFormationInfos.Count > formationIndex ? this._fieldBattleFormationInfos[formationIndex] : (OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) null);
    }

    public void SetFormationInfos(
      List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData> formationInfos,
      bool isSiegeBattle)
    {
      if (isSiegeBattle)
        this._siegeFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>((IEnumerable<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>) formationInfos);
      else
        this._fieldBattleFormationInfos = new List<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>((IEnumerable<OrderOfBattleCampaignBehavior.OrderOfBattleFormationData>) formationInfos);
    }

    public class OrderOfBattleFormationData
    {
      [SaveableField(1)]
      public readonly Hero Commander;
      [SaveableField(2)]
      public readonly DeploymentFormationClass FormationClass;
      [SaveableField(3)]
      public readonly int PrimaryClassWeight;
      [SaveableField(4)]
      public readonly int SecondaryClassWeight;
      [SaveableField(5)]
      public readonly Dictionary<FormationFilterType, bool> Filters;
      [SaveableField(6)]
      public readonly Hero[] HeroTroops;

      public OrderOfBattleFormationData(
        Hero commander,
        List<Hero> heroTroops,
        DeploymentFormationClass formationClass,
        int primaryWeight,
        int secondaryWeight,
        Dictionary<FormationFilterType, bool> filters)
      {
        this.Commander = commander;
        this.HeroTroops = heroTroops.ToArray();
        this.FormationClass = formationClass;
        this.PrimaryClassWeight = primaryWeight;
        this.SecondaryClassWeight = secondaryWeight;
        this.Filters = new Dictionary<FormationFilterType, bool>();
        foreach (FormationFilterType key in filters.Keys)
          this.Filters.Add(key, filters[key]);
      }

      internal static void AutoGeneratedStaticCollectObjectsOrderOfBattleFormationData(
        object o,
        List<object> collectedObjects)
      {
        ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        collectedObjects.Add((object) this.Commander);
        collectedObjects.Add((object) this.Filters);
        collectedObjects.Add((object) this.HeroTroops);
      }

      internal static object AutoGeneratedGetMemberValueCommander(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).Commander;
      }

      internal static object AutoGeneratedGetMemberValueFormationClass(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).FormationClass;
      }

      internal static object AutoGeneratedGetMemberValuePrimaryClassWeight(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).PrimaryClassWeight;
      }

      internal static object AutoGeneratedGetMemberValueSecondaryClassWeight(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).SecondaryClassWeight;
      }

      internal static object AutoGeneratedGetMemberValueFilters(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).Filters;
      }

      internal static object AutoGeneratedGetMemberValueHeroTroops(object o)
      {
        return (object) ((OrderOfBattleCampaignBehavior.OrderOfBattleFormationData) o).HeroTroops;
      }
    }
  }
}
